package in.muton.edushare.panels.assignment;

import in.muton.edushare.pages.EduShareBasePage;
import in.muton.edushare.pages.common.EdusharePanel;

import java.util.HashMap;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;

import com.edushare.common.dao.UserAssignmentLinkDAO;
import com.edushare.common.vo.Assignments;
import com.edushare.common.vo.UserAssignmentLink;

public class SubmissionsProfView extends EdusharePanel {

	private static final long serialVersionUID = 7909709478432767433L;
	private IModel<Assignments> assnModel;
	private HashMap<Integer, Integer> submissionStats;
	
	public SubmissionsProfView(String id, EduShareBasePage page, IModel<Assignments> assnModel) {
		super(id, assnModel, page);
		this.assnModel = assnModel;
		loadPanel(page);
	}

	private void loadPanel(EduShareBasePage page) {
		add(new Label("assnStat", Assignments.getStatusAsString(assnModel.getObject().getStatus()).toUpperCase()));
		submissionStats = new UserAssignmentLinkDAO(getORMInterface()).getSubmissionsStats(this.assnModel.getObject());
		add(new Label("totalStat", new PropertyModel<String>(this, "totalStat")));
		add(new Label("intimeStat", new PropertyModel<String>(this, "intimeStat")));
		add(new Label("lateStat", new PropertyModel<String>(this, "lateStat")));
		add(new Label("pendingStat", new PropertyModel<String>(this, "pendingStat")));
		add(new Label("defaultedStat", new PropertyModel<String>(this, "defaultedStat")));
		
		//load listings panel
		add(new SubmittersList("submissionList",page, this.assnModel));
		
	}

	public int getTotalStat(){
		return getIntimeStat()+getLateStat()+getPendingStat()+getDefaultedStat();
	}
	
	public int getIntimeStat(){
		if(this.submissionStats.get(UserAssignmentLink.STATUS_SUBMISSION_DONE)!=null)
			return this.submissionStats.get(UserAssignmentLink.STATUS_SUBMISSION_DONE);
		else
			return 0;
	}
	
	public int getLateStat(){
		if(this.submissionStats.get(UserAssignmentLink.STATUS_SUBMISSION_LATE)!=null)
			return this.submissionStats.get(UserAssignmentLink.STATUS_SUBMISSION_LATE);
		else
			return 0;
	}
	
	public int getPendingStat(){
		if(this.submissionStats.get(UserAssignmentLink.STATUS_SUBMISSION_PENDING)!=null)
			return this.submissionStats.get(UserAssignmentLink.STATUS_SUBMISSION_PENDING);
		else
			return 0;
	}
	
	public int getDefaultedStat(){
		if(this.submissionStats.get(UserAssignmentLink.STATUS_SUBMISSION_NONE)!=null)
			return this.submissionStats.get(UserAssignmentLink.STATUS_SUBMISSION_NONE);
		else
			return 0;
	}
	
	
}
